﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;


namespace Hangman
{
    public class Imagepusher : IHttpHandler
    {

        public bool IsReusable
        {
            get { return false; }
        }

        Bitmap image;


        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/gif";

            string imageStatus = context.Server.UrlDecode(context.Request.QueryString["status"]);

            //string path = Imagepath + "/";
            string path = "~/Images/";

            switch (imageStatus)
            {
                case "0":
                    path += "state00.gif";
                    break;
                case "1":
                    path += "state01.gif";
                    break;
                case "2":
                    path += "state02.gif";
                    break;
                case "3":
                    path += "state03.gif";
                    break;
                case "4":
                    path += "state04.gif";
                    break;
                case "5":
                    path += "state05.gif";
                    break;
                default:
                    path += "state00.gif";
                    break;
            }

            //image = new Bitmap(path);
            //image = new Bitmap(context.Server.MapPath("~/Images/state00.gif"));
            image = new Bitmap(context.Server.MapPath(path));
            /*Graphics gfx = Graphics.FromImage(image);
            gfx.FillRectangle(Brushes.DarkOrange, new Rectangle(0, 0, 800, 600));
            Font font = new Font("Sans", 40);
            gfx.DrawString(str, font, Brushes.Black, 200, 200);*/
            image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
            image.Dispose();
        }
    }
}